/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */
package com.yami.shop.api.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.esotericsoftware.minlog.Log;
import com.yami.shop.bean.app.dto.ArticleDto;
import com.yami.shop.bean.model.Article;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.ArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @author lanhai
 */
@RestController
@Slf4j
@RequestMapping("/shop/article")
@Tag(name = "公告管理接口")
@AllArgsConstructor
//手机端控制器
public class ArticleController {

    private ArticleService articleService;

    

    /**
     * 置顶公告列表接口
     */
    @GetMapping("/topArticleList")
    @Operation(summary = "置顶公告列表信息" , description = "获取所有置顶公告列表信息")
    public ServerResponseEntity<List<ArticleDto>> getTopArticleList() {
        List<Article> articleList = articleService.listArticle();
        List<ArticleDto> articleDtoList = BeanUtil.copyToList(articleList, ArticleDto.class);
        return ServerResponseEntity.success(articleDtoList);
    }

    /**
     * 获取公告详情
     */
    @GetMapping("/info/{id}")
    @Operation(summary = "公告详情" , description = "获取公告id公告详情")
    public ServerResponseEntity<ArticleDto> getArticleById(@PathVariable("id") Long id) {
        Article article = articleService.getArticleById(id);
        // System.out.println(article);
        
        log.info("article内容: {}", article);

        ArticleDto articleDto = BeanUtil.copyProperties(article, ArticleDto.class);
        return ServerResponseEntity.success(articleDto);
    }

    /**
     * 公告列表
     */
    @GetMapping("/articleList")
    @Operation(summary = "公告列表信息" , description = "获取所有公告列表信息")
    @Parameters({
    })
    public ServerResponseEntity<IPage<ArticleDto>> pageArticle(PageParam<ArticleDto> page) {

        return ServerResponseEntity.success(articleService.pageArticle(page));
    }
}